﻿// -----------------------------------------------------------------------
// <copyright file="Utils.cs" company="Softserve">
// Utility for WebServer
// </copyright>
// -----------------------------------------------------------------------
namespace WebServer.BusinessLogic.Helpers
{
    using System.IO;

    /// <summary>
    /// class which contain utilities for WebServer
    /// </summary>
    public static class Utils
    {
        /// <summary>
        /// Reading file from memory
        /// </summary>
        /// <param name="filePath">path to the file</param>
        /// <returns>data of file</returns>
        public static byte[] ReadBytesFromFile(string filePath)
        {
            byte[] buffer;
            using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
            {
                int count;
                int sum = 0;
                long length = fs.Length;
                buffer = new byte[length];
                while ((count = fs.Read(buffer, sum, (int)(length - sum))) > 0)
                {
                    sum += count;
                }
            }

            return buffer;
        }
    }
}
